home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0119_Compilation Dates - Preprocessor.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  117 lines

  1. (*
  2. > Is it possible to display date and time of compilation from
  3. > a program compiled under Borland Pascal?  If yes, how?
  4.  
  5. if you mean like C programs can do, yes it is possible. it takes an
  6. external utility, a .BAT file, and a "special" line in your program's
  7. CONST section. C programs have a preprocessor that looks for and
  8. replaces tokens with certain information. we just create our own for
  9. this special need/desire...
  10.  
  11. here's what the "special" line in the program source has to look like...
  12. if it doesn't look just like this, it will NOT work correctly...
  13.  
  14. const
  15.   progname      : string[6]  = 'PostIt';
  16.   MergeCode     : string[57] = 'Product of Quartz Crystal Software';
  17. > {$I compiled}
  18.   cfgfile       : string[10] = 'POSTIT.CFG';
  19.   tearline      : string[4]  = '--- ';
  20.  
  21.  
  22. the key to this is that you have to have the line in a section of
  23. CONST's that are actually used. if none of the other four CONST's above
  24. were used in the program, the time and date of the compile would not be
  25. included in the final .EXE file. whether you display it on the screen or
  26. not is your choice.
  27.  
  28.  
  29. first, the .BAT file i use to compile programs with...
  30.  
  31. @echo off
  32. rem **********************************************************
  33. rem * COMPIT.BAT                                             *
  34. rem *                                                        *
  35. rem * uses a 4DOS specific option %& to pass the rest of the *
  36. rem * command line on to the TPC compiler                    *
  37. rem *                                                        *
  38. rem * TPPP is our Turbo Pascal PreProcessor utility <<smile>>*
  39. rem **********************************************************
  40. if exist compiled.pas del compiled.pas
  41. if '%1' == '' goto error
  42. tppp
  43. tpc /ic:\tp /uc:\tp /tc:\tp /oc:\tp %&
  44. goto end
  45. :error
  46. echo 
  47. echo What file to compile?
  48. echo.
  49. echo  ie: COMPIT thisfile.pas
  50. echo.
  51. :end
  52.  
  53.  
  54. now the source to TPPP...
  55. *)
  56.  
  57. program Turbo_Pascal_Pre_Processor;
  58.  
  59. { this program started out as a preprocessor but i've not had a }
  60. { chance to do more with it than to hard code only a time/date  }
  61. { string for an include file :(                                 }
  62.  
  63. uses Dos;
  64.  
  65. var thefile : text;
  66.  
  67. function DATE : string;
  68. const
  69.   months : array [1..12] of String[3] =
  70.     ('Jan','Feb','Mar','Apr','May','Jun',
  71.      'Jul','Aug','Sep','Oct','Nov','Dec');
  72. var
  73.   y, m, d, dow : Word;
  74.   daystr  : string;
  75.   yearstr : string;
  76. begin
  77.   GetDate(y,m,d,dow);
  78.   str(d,daystr);
  79.   str(y,yearstr);
  80.   DATE := daystr + ' ' + months[m] + ' ' + yearstr;
  81. end;
  82.  
  83. function TIME : string;
  84. var
  85.   h, m, s, hund : Word;
  86.   function LeadingZero(w : Word) : String;
  87.   var
  88.     s : String;
  89.   begin
  90.     Str(w:0,s);
  91.     if Length(s) = 1 then
  92.       s := '0' + s;
  93.     LeadingZero := s;
  94.   end;
  95. begin
  96.   GetTime(h,m,s,hund);
  97.   TIME := LeadingZero(h) + ':' + LeadingZero(m);
  98. end;
  99.  
  100. begin
  101.   assign(thefile,'COMPILED.PAS');
  102.   rewrite(thefile);
  103.   writeln(thefile,
  104.     'compiled : string[32] = ''Compiled on ',DATE,' at ',TIME,''';');
  105.   close(thefile);
  106. end.
  107.  
  108. {
  109. TPPP was originally going to process source code files that comtained
  110. tokens like C coders can use. something similar to the following...
  111.  
  112.   compiled : string[32] = 'Compiled on __DATE__ at __TIME__';
  113.  
  114. i've just not had the time to complete any more of the design and coding
  115. needed... this suits my desires for now...
  116. {
  117.